//
//  CountGameViewController.m
//  Diary
//
//  Created by lanou3g on 16/1/12.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "CountGameViewController.h"
#import "AppDelegate.h"
#import "Count.h"
@interface CountGameViewController ()
{
    int i;//用于计数（题的个数）
    int _calculateCount1;//用来判断两位数的计算的符号
    int _calculateCount2;//用来判断三位数的计算的符号
    int _calculateCount3;//用来判断四位数的计算的符号
    NSTimer *timer;//用来计时
    int timerCount;//算题的时间
    UIView *endView;//游戏失败后的View
    
    
}
@property (strong, nonatomic) IBOutlet UILabel *calculateCount;

@property (strong, nonatomic) IBOutlet UILabel *countLabel;

@property (strong, nonatomic) IBOutlet UILabel *num1;


@property (strong, nonatomic) IBOutlet UILabel *symbol;

@property (strong, nonatomic) IBOutlet UILabel *num2;


@property (strong, nonatomic) IBOutlet UILabel *symbol1;

@property (strong, nonatomic) IBOutlet UILabel *num4;


@property (strong, nonatomic) IBOutlet UILabel *symbol2;

@property (strong, nonatomic) IBOutlet UILabel *num5;



@end

@implementation CountGameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //用于计数（题的个数）
    i = 0;
    
        
        _calculateCount1 = arc4random()%2;
    
        
        _symbol1.hidden = YES;
        _num4.hidden = YES;
        _symbol2.hidden = YES;
        _num5.hidden = YES;

        timerCount = 10;
         _calculateCount.text = [NSString stringWithFormat:@"%d",timerCount];
    
        if (_calculateCount1 == 0) {
            
            [self calculate];
            [timer invalidate];
            
        }
        
        else{
            
            [self calculate];
            [timer invalidate];
        }

        
        
    
    //用于计数（题的个数）
    i = 0;
    _countLabel.text = [NSString stringWithFormat:@"本次成绩 : %d",i];
    
    
    
    
}




//1
- (IBAction)button1:(id)sender {
    if (i<=5) {
        [self calculate1:1];
    }
//    if (i>5) {
//        
//        [self calculate2:1];
//    }
    else{
        [self calculate3:1];
    }
}

//2
- (IBAction)button2:(id)sender {
    
    if (i<=5) {
        [self calculate1:2];
    }
//    if (i>5) {
//        
//        [self calculate2:2];
//    }
    else{
        [self calculate3:2];
    }

    
}

//3
- (IBAction)button3:(id)sender {
    
    if (i<=5) {
        [self calculate1:3];
    }
//    if (i>5) {
//        
//        [self calculate2:3];
//    }
    else{
        [self calculate3:3];
    }

    
}

//4
- (IBAction)button4:(id)sender {
    
    if (i<=5) {
        [self calculate1:4];
    }
//    if (i>5) {
//        
//        [self calculate2:4];
//    }
    else{
        [self calculate3:4];
    }

    
}

//5
- (IBAction)button5:(id)sender {
    
    if (i<=5) {
        [self calculate1:5];
    }
//    if (i>5) {
//    
//        [self calculate2:5];
//    }
    else{
        [self calculate3:5];
    }

    
}

//6
- (IBAction)button6:(id)sender {
    
    if (i<=5) {
        [self calculate1:6];
    }
//    if (i>5) {
//    
//        [self calculate2:6];
//    }
    else{
        [self calculate3:6];
    }

    
    
}


- (void)calculate{
    
    
        i++;
        _countLabel.text = [NSString stringWithFormat:@"本次成绩 : %d",i];
 
   
    NSLog(@"%d",i);
 
    
    if (i<=5) {
        timerCount = 10;
        [timer invalidate];
        timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateMusic) userInfo:nil repeats:YES];
        
       
        
        _calculateCount1 = arc4random()%2;
        
        if (_calculateCount1 == 0) {
            
            self.symbol.text = @"+";
        }
        else{
            
            self.symbol.text = @"-";
        }
        
        while (1) {
            
            
            int num2 = arc4random()%4;
            int num1 = arc4random()%4;
            if (_calculateCount1 == 0 && 0<num1+num2 && num1+num2<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                
                break;
            }
            
            if (_calculateCount1 == 1 && 0<num1-num2 && num1-num2<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                
                break;
            }
            
        }
        
        
    }
  
  
/*
    if (i >5) {
        
        timerCount = 30;
        [timer invalidate];
        timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateMusic) userInfo:nil repeats:YES];
        
        _symbol1.hidden = NO;
        _num4.hidden = NO;
        
        //第一个符号
        _calculateCount1 = arc4random()%2;
        
        if (_calculateCount1 == 0) {
            
            self.symbol.text = @"+";
        }
        else{
            
            self.symbol.text = @"-";
        }
        
        //第二个符号
        _calculateCount2 = arc4random()%2;
        
        if (_calculateCount2 == 0) {
            
            self.symbol1.text = @"+";
        }
        else{
            
            self.symbol1.text = @"-";
        }
        
        
        
        while (1) {
            
            
            int num2 = arc4random()%4;
            int num1 = arc4random()%4;
            int num4 = arc4random()%4;
            if (_calculateCount1 == 0 && _calculateCount2 == 0 && 0<num1+num2+num4 && num1+num2+num4<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                
                return;
            }
            
            if (_calculateCount1 == 0 && _calculateCount2 == 1 && 0<num1+num2-num4 && num1+num2-num4<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                
                return;
            }
            
            if (_calculateCount1 == 1 && _calculateCount2 == 1 && 0<num1-num2-num4 && num1-num2-num4<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                
                return;
            }
            
            if (_calculateCount1 == 1 && _calculateCount2 == 0 && 0<num1-num2+num4 && num1-num2+num4<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                
                return;
            }
            
        }
        
        
    }
 */
    if (i>5) {
        
        if (i>5) {
            
            timerCount = 40;
        }
        
        if (i>10) {
            
             timerCount = 30;
        }
        
        if (i>15) {
            
             timerCount = 20;
        }
        
        if (i>20) {
            
            timerCount = 15;
        }
        
        if (i>30) {
            
            timerCount = 10;
        }
        
        if (i>35) {
            
            timerCount = 7;
        }
        
        [timer invalidate];
        timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateMusic) userInfo:nil repeats:YES];
        _symbol1.hidden = NO;
        _num4.hidden = NO;
        _symbol2.hidden = NO;
        _num5.hidden = NO;
        
        //第一个符号
        _calculateCount1 = arc4random()%2;
        
        if (_calculateCount1 == 0) {
            
            self.symbol.text = @"+";
        }
        else{
            
            self.symbol.text = @"-";
        }
        
        //第二个符号
        _calculateCount2 = arc4random()%2;
        
        if (_calculateCount2 == 0) {
            
            self.symbol1.text = @"+";
        }
        else{
            
            self.symbol1.text = @"-";
        }
        
        //第三个符号
        _calculateCount3 = arc4random()%2;
        
        if (_calculateCount3 == 0) {
            
            self.symbol2.text = @"+";
        }
        else{
            
            self.symbol2.text = @"-";
        }

        
        while (1) {
            
            
            int num2 = arc4random()%4;
            int num1 = arc4random()%4;
            int num4 = arc4random()%4;
            int num5 = arc4random()%4;
            if (_calculateCount1 == 0 && _calculateCount2 == 0 && _calculateCount3 == 0 && 0<num1+num2+num4+num5 && num1+num2+num4+num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
            if (_calculateCount1 == 0 && _calculateCount2 == 0 && _calculateCount3 == 1 && 0<num1+num2+num4-num5 && num1+num2+num4-num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
            if (_calculateCount1 == 0 && _calculateCount2 == 1 && _calculateCount3 == 1 && 0<num1+num2-num4-num5 && num1+num2-num4-num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
            if (_calculateCount1 == 1 && _calculateCount2 == 1 && _calculateCount3 == 1 && 0<num1-num2-num4-num5 && num1-num2-num4-num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
            if (_calculateCount1 == 1 && _calculateCount2 == 1 && _calculateCount3 == 0 && 0<num1-num2-num4+num5 && num1-num2-num4+num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }

            if (_calculateCount1 == 1 && _calculateCount2 == 0 && _calculateCount3 == 0 && 0<num1-num2+num4+num5 && num1-num2+num4+num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }

            if (_calculateCount1 == 0 && _calculateCount2 == 1 && _calculateCount3 == 0 && 0<num1+num2-num4+num5 && num1+num2-num4+num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
            if (_calculateCount1 == 1 && _calculateCount2 == 0 && _calculateCount3 == 1 && 0<num1-num2+num4-num5 && num1-num2+num4-num5<7) {
                
                self.num1.text = [NSString stringWithFormat:@"%d",num1];
                self.num2.text = [NSString stringWithFormat:@"%d",num2];
                _num4.text = [NSString stringWithFormat:@"%d",num4];
                _num5.text = [NSString stringWithFormat:@"%d",num5];
                
                return;
            }
            
        }
        

        
    }
    
    
}

//计算二位数
- (void)calculate1:(int)count{
    
    if (_calculateCount1 == 0) {
        
        NSInteger result0 = [self.num1.text integerValue] + [self.num2.text integerValue];
        
        if (result0 == count) {
            
            
            [self calculate];
            return;
        }
        if (result0 != count) {
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋＋＋＋＋＋＋");
        }
        
    }
    
    if (_calculateCount1 == 1) {
        
        NSInteger result = [self.num1.text integerValue] - [self.num2.text integerValue];
        if (result == count) {
            
            
            
            [self calculate];
            return;
        }
        if (result != count) {
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋－－－－－－");
        }
        
    }
    
    
}

//计算三位数
- (void)calculate2:(int)count2{
    
    //+ +
    if (_calculateCount1 == 0 && _calculateCount2 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] + [self.num4.text integerValue];
        
        if (result1 == count2) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋");
        }
        
    }
    
    //- -
    
    if (_calculateCount1 == 1 && _calculateCount2 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] - [self.num4.text integerValue];
        
        if (result1 == count2) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋");
        }
        
    }
    
    //+　-
    
    if (_calculateCount1 == 0 && _calculateCount2 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] - [self.num4.text integerValue];
        
        if (result1 == count2) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋000000");
        }
        
    }
    
    //- +
    if (_calculateCount1 == 1 && _calculateCount2 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] + [self.num4.text integerValue];
        
        if (result1 == count2) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }
    
}

//四位数计算
- (void)calculate3:(int)count3{
    
    
    //+ + +
    if (_calculateCount1 == 0 && _calculateCount2 == 0 && _calculateCount3 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] + [self.num4.text integerValue] + [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋");
        }
        
    }
    
    //+ + -
    
    if (_calculateCount1 == 0 && _calculateCount2 == 0 && _calculateCount3 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] + [self.num4.text integerValue] - [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋");
        }
        
    }
    
    //+ -　-
    
    if (_calculateCount1 == 0 && _calculateCount2 == 1 && _calculateCount3 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] - [self.num4.text integerValue] - [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            [self gameOverView];
            [timer invalidate];
            
            NSLog(@"笨蛋000000");
        }
        
    }
    
    //- - -
    if (_calculateCount1 == 1 && _calculateCount2 == 1 && _calculateCount3 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] - [self.num4.text integerValue] - [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }

    //- - +
    if (_calculateCount1 == 1 && _calculateCount2 == 1 && _calculateCount3 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] - [self.num4.text integerValue] + [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }

    //- + +
    if (_calculateCount1 == 1 && _calculateCount2 == 0 && _calculateCount3 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] + [self.num4.text integerValue] + [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }

    //+ - +
    if (_calculateCount1 == 0 && _calculateCount2 == 1 && _calculateCount3 == 0) {
        
        NSInteger result1 = [self.num1.text integerValue] + [self.num2.text integerValue] - [self.num4.text integerValue] + [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }

    //- + -
    if (_calculateCount1 == 1 && _calculateCount2 == 0 && _calculateCount3 == 1) {
        
        NSInteger result1 = [self.num1.text integerValue] - [self.num2.text integerValue] + [self.num4.text integerValue] - [self.num5.text integerValue];
        
        if (result1 == count3) {
            
            
            [self calculate];
            return;
            
        }else{
            
            NSLog(@"笨蛋1111111");
            [self gameOverView];
            [timer invalidate];
            
        }
        
    }

}


- (void)updateMusic{
    
    timerCount--;
    _calculateCount.text = [NSString stringWithFormat:@"%d",timerCount];
    if (timerCount==0) {
        [timer invalidate];
         _button1.userInteractionEnabled = YES;
         _button2.userInteractionEnabled = YES;
         _button3.userInteractionEnabled = YES;
         _button4.userInteractionEnabled = YES;
         _button5.userInteractionEnabled = YES;
         _button6.userInteractionEnabled = YES;
        [self gameOverView];
    }
    
}

- (void)gameOverView{
    
    //改变透明度
    [self smallerAlpha];
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    //创建搜索请求对象，并且指明所有的数据类型
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Count"];
    NSArray *objcArray = [app.managedObjectContext executeFetchRequest:request error:nil];
    num = [NSNumber numberWithInt:i];
    
    if (objcArray.count == 0) {
        
        [self firstSave:num];
    }
    
    for (Count *count in objcArray) {
        
        
        if (count.count < num) {
            
            [self delete];
    
            [self firstSave:num];
        }
   
    }
    

    endView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    endView.backgroundColor = [UIColor clearColor];
    endView.userInteractionEnabled = YES;
    [self.view addSubview:endView];
    
    
    
    
    
    if (ScreenFrame_Widdth == 320) {
        
        bigCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 300, 120, 30)];
        
        countLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(100, 350, 120, 30)];
        
        startButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 120, 30)];
        
    }
    if (ScreenFrame_Widdth == 375) {
        
        bigCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 350, 120, 30)];
        
        countLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(130, 400, 120, 30)];
        
        startButton = [[UIButton alloc] initWithFrame:CGRectMake(130, 450, 120, 30)];
    }
    if (ScreenFrame_Widdth == 414) {
        
        bigCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 400, 120, 30)];
        
        countLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(150, 450, 120, 30)];
        
        startButton = [[UIButton alloc] initWithFrame:CGRectMake(150, 500, 120, 30)];
    }
    
    testResultLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenFrame_Widdth/2-140, 100, 280, 90)];
    testResultLabel.numberOfLines = 0;
    testResultLabel.textAlignment = NSTextAlignmentCenter;
    testResultLabel.font = [UIFont systemFontOfSize:25];
    testResultLabel.backgroundColor = [UIColor clearColor];
    [endView addSubview:testResultLabel];
    
    if (i<=5) {
        
        testResultLabel.text = @"测试结果 : 大笨蛋,你是日本人吗？";
        
    }
    
    if (i>5&&i<=10) {
        
       testResultLabel.text = @"测试结果 :  还是笨蛋,中国人没这么笨!";
        
    }
    
    if (i>10&&i<15) {
        
        testResultLabel.text = @"测试结果 :  正常人,你是中国人!";
        
    }
    
    if (i>=15&&i<=20) {
        
        testResultLabel.text = @"测试结果 :  牛人!你看你就是内蒙古的!";
        
    }
    
    
    if (i>20&&i<=30) {
        
        testResultLabel.text = @"测试结果 :  不是人!!!";
        
    }
    
    if (i>30&&i<=40) {
        
        testResultLabel.text = @"测试结果 :  神仙!!!";
        
    }
    
    if (i>40) {
        
        testResultLabel.text = @"测试结果 :  送你个QQ号吧:850670620";
        
    }
    
    bigCountLabel.backgroundColor = [UIColor blueColor];
    bigCountLabel.layer.cornerRadius = 10;
    bigCountLabel.clipsToBounds = YES;//iOS7之后需要设置
    bigCountLabel.textColor = [UIColor whiteColor];
    bigCountLabel.textAlignment = NSTextAlignmentCenter;
    [endView addSubview:bigCountLabel];
    [self results];
    
    countLabel1.backgroundColor = [UIColor blueColor];
    countLabel1.layer.cornerRadius = 10;
    countLabel1.clipsToBounds = YES;//iOS7之后需要设置
    countLabel1.text = [NSString stringWithFormat:@"本次成绩 : %d",i];
    countLabel1.textColor = [UIColor whiteColor];
    countLabel1.textAlignment = NSTextAlignmentCenter;
    [endView addSubview:countLabel1];
    
    [startButton addTarget:self action:@selector(return1) forControlEvents:UIControlEventTouchUpInside];
    [startButton setTitle:@"重新开始" forState:UIControlStateNormal];
    startButton.backgroundColor = [UIColor blueColor];
    startButton.layer.cornerRadius = 10;
    startButton.clipsToBounds = YES;//iOS7之后需要设置
    startButton.userInteractionEnabled = YES;
    [endView addSubview:startButton];
    
    
}

- (void)return1{
    
    [endView removeFromSuperview];
    
    [self viewDidLoad];
    timerCount = 30;
    
    [self biggerAlpha];
}


//改变透明度(小)
- (void)smallerAlpha{
    
    _calculateCount.alpha = 0.2;
    _countLabel.alpha = 0.2;
    _num1.alpha = 0.2;
    _symbol.alpha = 0.2;
    _num2.alpha = 0.2;
    _symbol1.alpha = 0.2;
    _num4.alpha = 0.2;
    _symbol2.alpha = 0.2;
    _num5.alpha = 0.2;
    _button1.alpha = 0.2;
    _button2.alpha = 0.2;
    _button3.alpha = 0.2;
    _button4.alpha = 0.2;
    _button5.alpha = 0.2;
    _button6.alpha = 0.2;
    _symbol3.alpha = 0.2;
    _symbol4.alpha = 0.2;
    
}
//改变透明度(恢复)
- (void)biggerAlpha{
    
    _calculateCount.alpha = 1;
    _countLabel.alpha = 1;
    _num1.alpha = 1;
    _symbol.alpha = 1;
    _num2.alpha = 1;
    _symbol1.alpha = 1;
    _num4.alpha = 1;
    _symbol2.alpha = 1;
    _num5.alpha = 1;
    _button1.alpha = 1;
    _button2.alpha = 1;
    _button3.alpha = 1;
    _button4.alpha = 1;
    _button5.alpha = 1;
    _button6.alpha = 1;
    _symbol3.alpha = 1;
    _symbol4.alpha = 1;
}

- (void)firstSave:(NSNumber *)count{
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    Count *count1 = [NSEntityDescription insertNewObjectForEntityForName:@"Count" inManagedObjectContext:app.managedObjectContext];
    count1.count = count;
    [app saveContext];
}

- (void)delete{
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Count"];
    NSPredicate *cata = [NSPredicate predicateWithFormat:@"count>0"];//获取当前行的内容(数据库中的)
    request.predicate = cata;
    NSArray *array = [app.managedObjectContext executeFetchRequest:request error:nil];
    
    for (Count *count in array) {
        [app.managedObjectContext deleteObject:count];
    }
    
    if ([app.managedObjectContext hasChanges]) {
        [app.managedObjectContext save:nil];
    }
    
}


- (void)results{
    
    AppDelegate *app1 = [UIApplication sharedApplication].delegate;
    //创建搜索请求对象，并且指明所有的数据类型
    NSFetchRequest *request1 = [[NSFetchRequest alloc] initWithEntityName:@"Count"];
    NSArray *objcArray1 = [app1.managedObjectContext executeFetchRequest:request1 error:nil];
    
    for (Count *count in objcArray1) {
       
        if (count.count < num) {
            
            bigCountLabel.text = [NSString stringWithFormat:@"新纪录 : %@",count.count];
            
        }
        else{
            
            bigCountLabel.text = [NSString stringWithFormat:@"最高成绩 : %@",count.count];
            
        }
        
        
        
    }

    
}


@end
